<?php


require ROOT_PATH.'/Helper/admin_base_abstract.php';

class Action extends admin_base_abstract
{
    function __construct($controller)
    {
        parent::__construct($controller);
        // allready login
        if (!empty($_SESSION['admin_user'])) {
            $this->redirect('admin');
        }
    }

    function index()
    {
        if (Request::isPost()) {
            $user_name = _POST('user_name');
            $password = _POST('password');
            
            if (!$info = _model('user')->getInfoByName($user_name)) {
                $this->msg('not exists');
            }

            if ($info['password'] != md5($password)) {
                $this->msg('password wrong');
            }
            if (!$info['user_group']) {
                $this->msg('no permission');
            }

            unset($info['password']);
            $_SESSION['admin_user'] = $info;
            $this->redirect('admin');
        } else {
            $this->view->display('admin/login.html');
        }
    }
}

?>